package org.example.service;

import org.example.dao.UserMapper;
import org.example.model.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class UserServiceImpl implements UserService {
     @Autowired
     UserMapper userMapper;
    public String login(String username, String password) {
        User user = userMapper.login(username, password);
        if(user != null) {
            return "success";
        }else{
            return "fail";
        }
    }

    public List<User> getUserList(String username) {
         List<User> userList = userMapper.getUserList(username);
         return userList;
    }

    @Override
    public String addUser(User user) {
       int i= userMapper.addUser(user);
       if(i>0){
           return "success";
       }else {
           return "fail";
       }

    }

    @Override
    public String deleteUser(int id) {
        int i =userMapper.deleteUser(id);
        if(i>0){
            return "success";
        }else {
            return "fail";
        }

    }

    @Override
    public String updateUser(User user) {
       int i = userMapper.updateUser(user);
       if(i>0){
           return "success";
       }else{
           return "fail";
       }

    }
}
